﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CdcSoftware.Pivotal.Engine.Client.ClientTasks.Attributes;
using CdcSoftware.Pivotal.Engine.Client.Services.Interfaces;
using System.Collections;
using System.Data;
using System.Windows.Forms;
using CdcSoftware.Pivotal.Engine.UI.DataTypes.FormParams;
using CdcSoftware.Pivotal.Engine;
using CdcSoftware.Pivotal.Engine.Client.Types;
using CdcSoftware.Pivotal.Engine.ServerProxy;
using CdcSoftware.Pivotal.Engine.Types.DataTemplates;
using CdcSoftware.Pivotal.Engine.Types.Database;
using CdcSoftware.Pivotal.Engine.Types.Localization;
using CdcSoftware.Pivotal.Engine.Types.ServerTasks;
using CdcSoftware.Pivotal.Engine.UI;
using CdcSoftware.Pivotal.Engine.UI.Forms;
using CdcSoftware.Pivotal.Applications.Core.Client;
using CdcSoftware.Pivotal.Applications.Core.Common;

namespace Pcm.Retail.Client.FormTasks
{
    public class ContactCommandClientTask : CommandClientTask
    {
        [ClientTaskCommand]
        public virtual void LaunchMainWindowClientForm()
        {
            try
            {
                string title = "Open Main Window Client Form";

                IInputDialogService inputDialogService = ClientContext.ClientAPIService.GetService<IInputDialogService>();
                InputParamsCollection paramCollection = new InputParamsCollection();
                InputParam paramClientFormName = new InputParam();
                InputParam paramMessage = new InputParam();
                InputDialogStyle dialogStyle = new InputDialogStyle();
                dialogStyle.BoldLabels = true;

                paramClientFormName.Label = "Client Form Name: ";
                paramClientFormName.Type = InputParamType.String;
                paramCollection.Add(paramClientFormName);
                DialogResult dialogResult = inputDialogService.ShowDialog(paramCollection, dialogStyle, title);

                if (dialogResult != DialogResult.Cancel)
                {
                    string strClientFormName = TypeConvert.ToString(paramClientFormName.Value).Trim();

                    if (strClientFormName != String.Empty)
                    {
                        Globals.NewForm(strClientFormName, null);
                    }
                }
                else
                {
                    PivotalMessageBox.Show("You must enter a Client Form Name", MessageBoxButtons.OK);
                }
            }
            catch (Exception exc)
            {
                Globals.HandleException(exc, true);
            }
        }
    }
}
